#include "base2synsetconverter.h"

#include <QDir>
#include <QTextStream>

#include <QDebug>

Base2SynsetConverter::Base2SynsetConverter()
{
}

void Base2SynsetConverter::convert(const QString &inputFile, const QString &outputFile)
{
    QFile inFile(inputFile);
    QFile outFile(outputFile);
    QTextStream out(&outFile);

    inFile.open(QIODevice::ReadOnly);
    outFile.open(QIODevice::WriteOnly);
    QStringList words(QString(inFile.readAll()).split(' ', QString::SkipEmptyParts));

    foreach(const QString &word, words){
        QStringList synsets = dao.findSynsets(word);
        if(synsets.isEmpty())
            out << word << ' ';
        else
            out << synsets.join(" ") << ' ';
    }

    outFile.close();
}

void Base2SynsetConverter::convertAll(const QString &inputDir, const QString &outputDir)
{
    QDir inDir(inputDir);
    QStringList files(inDir.entryList(QDir::Files));
    int i = 1;
    foreach(const QString &file, files){
        convert(QString("%1/%2").arg(inputDir).arg(file), QString("%1/%2").arg(outputDir).arg(file));
        qDebug() << QString("converting %1/%2").arg(i).arg(files.size());
        i++;
    }
}
